# -*- coding: utf-8 -*-
# Author: xiantingDeng
# File: 05_异常.py
# Time: 20:00

#
# try:
#     # open("ddd.txt","r")
#     print(i)
# except FileNotFoundError as e:
#     print("如果捕获到异常后做的处理：{}".format(e))
# except Exception as e: # 如果用了Exception，那么上面的Except没有捕获到异常这个except一定会捕捉到
#     print("文件找不到了：{}".format(e))
# else:
#     print("无异常，我就执行")
# finally:
#     print("不管有无异常，我都会执行")
#
# print("2")
#


# import time
# try:
#     while True:
#         print("haha")
#         time.sleep(1)
# except Exception as e:
#     print("出现异常")


# 抛出自定义异常

class ShortInputException(Exception):
    def __init__(self,lenght,atleast):
        self.lenght = lenght
        self.atleast = atleast

def main():
    try:
        s = input("请输入：")
        if len(s) < 3:
            raise ShortInputException(len(s),3)
    except ShortInputException as e:
        print("StopAsyncIteration:输入的长度有误：{}".format(e))
    else:
        print("没有异常发生")
